package com.yc.home.cloudother.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.entity.Paper;
import com.yc.entity.PaperDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lzk
 * @since 2024-10-12
 */
public interface PaperMapper extends BaseMapper<Paper> {

    //关联查询
    @Select("select * from paper where id = #{id}")
    //关系映射
    @Results(
            id="rm1",
            value = {
                    @Result(column = "id", property = "id", id = true),
                    @Result(column = "id", property = "details", many = @Many(
                            select = "selectDetailsByPid"
                    ))
            }
    )
    Paper findByid(int id);


    @Select("select * from paper_detail where pid = #{id}")
    //关系映射
    @Results(
            id="rm2",
            value = {
                    @Result(column = "id", property = "id", id = true),
                    @Result(column = "qid", property = "qid", id = true),
                    @Result(column = "qid", property = "question", one = @One(
                            select = "com.yc.home.cloudother.mapper.QuestionMapper.selectById"
                    ))
            }
    )
    List<PaperDetail> selectDetailsByPid(int id);

}
